﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nucleic.Core.Utils
{
    public class TimerUtil
    {
        public async Task Run()
        {
            //间隔时间1秒
            using (var timer = new PeriodicTimer(TimeSpan.FromSeconds(1)))
            {
                //在到达指定周期后执行方法
                while (await timer.WaitForNextTickAsync())
                {
                    await Task.Delay(3000);

                    Console.WriteLine($"Timer Thread: {Thread.CurrentThread.ManagedThreadId}");
                    Console.WriteLine($"{DateTime.Now.Second} PeriodicTimer tick");
                }
            }
        }
    }
}
